/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import entity.PaymentEntity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import type.InvoiceType;

/**
 *
 * @author wei
 */
@Stateless
public class PaymentEntityFacade extends AbstractFacade<PaymentEntity> {
    @PersistenceContext(unitName = "MacTeam-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public PaymentEntityFacade() {
        super(PaymentEntity.class);
    }
    
    public List<PaymentEntity> getAllNormalPayments(){
        return getPaymentsByType(InvoiceType.normal);
    }
    
    public List<PaymentEntity> getAllCIAPayments(){
        return getPaymentsByType(InvoiceType.cashInAdvance);
    }
    
    public List<PaymentEntity> getAllReminderPayments(){
        return getPaymentsByType(InvoiceType.reminder);
    }
    
    public List<PaymentEntity> getPaymentsByType(InvoiceType type){
        List<PaymentEntity> payments = new ArrayList<PaymentEntity>();
        for(PaymentEntity p : findAll()){
            if(p.getInvoice().getType()==type)
                payments.add(p);
        }
        
        return payments;
    }
}
